from typing import List


"""1.两数之和"""


class Solution1:

    """方法1，双循环"""
    def twoSum1(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            for j in range(i + 1, len(nums)):
                if nums[i] + nums[j] == target:
                    return [i, j]
        return None

    """方法1，哈希表"""
    def twoSum2(self, nums: List[int], target: int) -> List[int]:
        dic = dict()
        for i, num in enumerate(nums):
            if target - num in dic.keys():
                return [i, dic[target - num]]
            dic[nums[i]] = i
        return None


if __name__ == '__main__':
    sl = Solution1()
    print(sl.twoSum2([2, 7, 11, 15], 9))